package com.youngjun.core.service.impl;

import com.youngjun.core.mapper.UserMapper;
import com.youngjun.core.pojo.domain.User;
import com.youngjun.core.pojo.dto.UserDTO;
import com.youngjun.core.pojo.vo.UserVO;
import com.youngjun.core.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    PasswordEncoder passwordEncoder;

    @Autowired
    UserMapper userMapper;

    @Override
    public UserMapper getMapper() {
        return userMapper;
    }

    @Override
    public List<UserVO> demo(UserDTO dto) {
//        List<UserVO> voList = getMapper()
//                .demo(new User().mapFrom(dto))
//                .stream()
//                .map(item -> new UserVO().mapFrom(item))
//                .collect(Collectors.toList());
        updateWithOptionalByPrimaryKey(select(new User().setUsername("test")));
        insert(new User());
//        batchInsertTest();
        return null;
    }

    @Override
    public void batchInsertTest() {
        List<User> list=new ArrayList<>();
        list.add(new User());
        list.add(new User());
        list.add(new User());
        getMapper().batchInsertTest(list);
    }

}